﻿using System;
using System.Collections.Generic;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Context;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Service;
using System.Linq;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Script;
using ZyGames.DZPocker.Tools;
using ZyGames.Framework.Common.Serialization;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 设置界面
	/// </summary>
	public class Action10060 : BaseAction
	{
		private int userId;
		private string selfInfoStr = "";
		private int savedNum = 0; //保存牌谱的数量
		private bool result = false;
		public Action10060(HttpGet actionGetter)
			: base((short)ActionType.DZApplySelfInfo, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("UserId", ref userId))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			var currentGameUser = GameTable.Current.GetUser(userId);
			if (currentGameUser == null)
			{
				Tool.WriteWarmingLine("消息10060玩家不存在");
				result = false;
				return true;
			}
			selfInfoStr = Convert.ToBase64String(ProtoBufUtils.Serialize(currentGameUser));
			//获得搜藏的牌谱数据
			this.savedNum = GameTable.Current.UserSavedCount(userId);
			result = true;
			return true;
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(this.result);
			this.PushIntoStack(this.selfInfoStr);
			this.PushIntoStack(this.savedNum);
		}
	}
}
